'''
with open('info.txt',mode='r',encoding='utf-8') as f:
    data = f.readlines()
    print(data) # 列表

# python2.7之后支持打开多个上下文管理文件
with open('info.txt',mode='r',encoding='utf-8') as f1, open('info2.txt',mode='r',encoding='utf-8') as f2:
    pass

'''

'''
# 日志计数
ip = '127.0.0.1'
count = 0
with open('log.txt',mode='r',encoding='utf-8')as f:
    for line in f:
        print(f)
        if not line.startswith(ip):
            continue
        count += 1
print(count)
'''

'''
# 日志计数升级版
ip_dict = {}

with open('log.txt',mode='r',encoding='utf-8')as f:
    for line in f:
        user_ip = line.split(' ')[0]
        if user_ip in ip_dict:
            # ip_dict[user_ip] = ip_dict[user_ip] +1
            ip_dict[user_ip] +=  +1
        else:
            ip_dict[user_ip] = 1
print(ip_dict)
'''

'''
# 帅选出股票 当前价大于20 的所有的股票数据
with open('stock.txt',mode='r',encoding='utf-8')as f:
    # 跳过第一行
    f.readline()
    # 接着往下读
    for line in f:
        price = line.split(',')[2]
        price = float(price)
        if price >20 :
            print(line)
            print(line.strip())
    
'''

# 根据要求修改文件内容
'''
- 文件读到内存，在通过replace替换（如果文件过大，这个方法就不好使）
- 一行一行读文件的内容，遇到要替换的内容就替换（其实是覆盖掉，长度不一样的话也还是没用）
- 同时打开两个文件，读+写（适用于大小文件）

# PEP6规范
with open('ha.conf',mode='r',encoding='utf-8') as r_f_obj,open('new.conf',mode='w',encoding='utf-8')as w_f_obj:
    for line in r_f_obj:
        new_line = line.replace('xxx','aaa')
        w_f_obj.write(new_line)
'''



import shutil
# 重命名文件
shutil.move('new.conf','ha.conf')


